<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>健康评估<small>心理测评</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>健康评估</el-breadcrumb-item>
            <el-breadcrumb-item>心理测评</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案号/姓名" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findSerchPage()" class="dalfBut">查询</el-button>
                <br/>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="mini" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" label="序号" align="center"></el-table-column>
                <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <!--Psychological evaluation date  心理测评日期-->
                <el-table-column prop="PED" label="心理测评日期" align="center"></el-table-column>
                <el-table-column prop="Somatization" label="躯体化" align="center"></el-table-column>
                <!--Obsessive compulsive disorder  强迫症化-->
                <el-table-column prop="OCD" label="强迫症化" align="center"></el-table-column>
                <!--Interpersonal sensitivity 人际关系敏感-->
                <el-table-column prop="IS" label="人际关系敏感" align="center"></el-table-column>
                <el-table-column prop="Hesitate" label="犹豫" align="center"></el-table-column>
                <el-table-column prop="Anxiety" label="焦虑" align="center"></el-table-column>
                <el-table-column prop="Hostility" label="敌对" align="center"></el-table-column>
                <!--Phobic Anxiety 恐怖-->
                <el-table-column prop="PA" label="恐怖" align="center"></el-table-column>
                <el-table-column prop="Paranoid" label="偏执" align="center"></el-table-column>
                <el-table-column prop="Psychoticism" label="精神病性" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <!--<el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>-->
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
                <el-table-column prop="remark" label="查看报告" align="center"></el-table-column>

            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName">
                            <el-form label-position="right" label-width="100px":rules="rules" >
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="档案号">
                                            <el-input v-model="formData.fileNumber"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-button type="primary" @click="findByfileId()">查询数据</el-button>
                                    </el-col>
                                </el-row>

                                <el-row>
                                    <el-col :span="6">
                                        <el-form-item label="姓名" prop="name">
                                            <el-input v-model="formData.name" :disabled="true"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="6">
                                        <el-form-item label="年龄" prop="age"/>
                                        <el-input v-model="formData.age" :disabled="true"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="6">
                                        <el-form-item label="性别" prop="gender">
                                            <el-input v-model="formData.sex" :disabled="true"/>
                                        </el-form-item>
                                    </el-col>
                             
                                </el-row>
                            </el-form>
                            <el-form>
                                <div>
                                    心理测评
                                </div>
                                <br/>

                                <div>
                                    <div id="u6490" class="text">
                                        <p><span>请根据近一年的感觉，回答以下问题</span></p>
                                    </div>
                                </div>
                                <!--c是单个题目-->
                                <p v-for="(c,i) in tableData"><span>{{c.psychoanalysis_test}}</span>
                                    <el-radio-group v-model="c.score" style="float: right">
                                        <el-radio label="1">从无</el-radio>
                                        <el-radio label="2">轻度</el-radio>
                                        <el-radio label="3">中度</el-radio>
                                        <el-radio label="4">偏重</el-radio>
                                        <el-radio label="5">严重</el-radio>
                                    </el-radio-group>
                                </p>
                            </el-form>

                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>


        </div>

    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            formData: {

            },//表单数据
            dataList: [],//列表数据
            tableData: [],//新增和编辑表单中对应的检查项列表数据
            psychoanalysisList: [],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                fileNumber: [{required: true, message: '档案号不为空', trigger: 'blur'}],
                name: [{required: true, message: '名字不为空', trigger: 'blur'}],
                gender: [{required: true, message: '性别不为空', trigger: 'blur'}],
                age: [{required: true, message: '年龄不为空', trigger: 'blur'}],
            }
        },
        created() {
            this.findPage();
        },
        methods: {
            findByfileId() {
                axios.get("/member/findByFileId.do?id=" + this.formData.fileNumber)
                    .then(res => {
                            console.log(res.data.data);
                        if (res.data.data.flag){
                            // this.name = res.name;
                            if (res.data.data.data.sex === "1") {
                                res.data.data.data.sex = '男';
                            } else {
                                res.data.data.data.sex = '女';
                            }
                            // this.age = res.age;
                            this.formData = res.data.data.data;
                            console.log(this.formData);
                        } else {

                            this.$message.error(res.message);
                        }
                    });
            },
            //编辑
            handleEdit() {
                //将选中的检查项ID赋值给formData
                this.formData.psychoanalysisIds = this.psychoanalysisIds;
                axios.post("/psychoanalysis/update.do", this.formData).then((res) => {
                    //判断后台返回的flag值，true表示编辑操作成功，false为编辑操作失败
                    if (res.data.flag) {
                        this.$message.success(res.data.message);
                    } else {
                        this.$message.error(res.data.message);
                    }
                }).finally(() => {
                    //隐藏编辑窗口
                    this.dialogFormVisible4Edit = false;
                    //调用分页查询方法
                    this.findPage();
                })
            },
            //添加
            handleAdd() {
                //将选中的检查项ID赋值给formData
                // this.formData.psychoanalysisIds = this.radio;
                if (this.formData.gender === '男') {
                    this.formData.gender = 1;
                } else {
                    this.formData.gender = 0;
                }
                this.formData.psychoanalysisList = this.tableData;

                this.formData.ptList = this.tableData
                axios.post("/psychoanalysis/add.do", this.formData).then((res) => {
                    //判断后台返回的flag值，true表示编辑操作成功，false为编辑操作失败
                    if (res.data.flag) {

                        this.$message.success(res.data.message);
                    } else {
                        this.$message.error(res.data.message);
                    }
                }).finally(() => {
                    //隐藏编辑窗口
                    this.dialogFormVisible = false;
                    //调用分页查询方法
                    this.findPage();
                })
            },
            //分页查询
            findPage() {
                //分页查询的参数
                var temple = this.pagination.queryString;
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: (temple != null && temple === "") ? null : temple
                };
                if (param.queryString != null) {
                    param.currentPage = 1;
                }
                //异步进行分页查询
                axios.post("/psychoanalysis/findPage.do", param).then((res) => {
                    //将分页查询的结果绑定到页面中
                    this.dataList = res.data.rows;
                    this.pagination.total = res.data.total;
                });
            },
            findSerchPage() {
                this.pagination.currentPage = 1;
                this.findPage();
            },
            // 重置表单
            resetForm() {
                this.formData = {};
                this.psychoanalysisList=[];
                this.fileNumber = "";
                this.name = "";
                this.gender = null;
                this.age = null;
                this.activeName = 'first';
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.findAll();
                this.dialogFormVisible = true;
            },


            // 弹出编辑窗口
            handleUpdate(row) {
                this.resetForm();
                //查询所有的检查项
                this.findAll();
                this.dialogFormVisible4Edit = true;
                //查询检查组信息
                axios.get("/psychoanalysis/findById/" + row.id + ".do").then((res) => {
                    if (res.data.flag) {
                        this.formData = res.data.data;
                        this.psychoanalysisIds = res.data.data.psychoanalysisIds;
                    } else {
                        this.$message.error(res.message);
                    }
                });
            },

            //查询全部测试题并赋值到心理测评表
            findAll() {
                //查询全部测试题并赋值到心理测评表
                axios.post("/psychoanalysis/findAll.do").then((res) => {
                    if (res.data.flag) {
                        this.tableData = res.data.data;
                    } else {
                        this.$message.error(res.data.message);
                    }
                });
            },
            //切换页码
            handleCurrentChange(currentPage) {
                //使用临时变量存储搜索框中数据
                var queryString = this.pagination.queryString;
                //修改搜索框中的数据为null
                this.pagination.queryString = null;
                //修改分页查询页码为选中页码
                this.pagination.currentPage = currentPage;
                //调用分页查询
                this.findPage();
                //将搜索框中数据重写回搜索框
                this.pagination.queryString = queryString;
            },
            // 删除
            handleDelete(row) {
                this.$confirm('此操作将删除条数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/psychoanalysis/delete/" + row.id + ".do").then((res) => {
                        if (res.data.flag) {
                            this.$message.success(res.data.message);
                        } else {
                            this.$message.error(res.data.message);
                            return false;
                        }
                    }).finally(() => {
                            this.findPage();
                        }
                    );
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    });
                });
            }
        }
    })
</script>

</html>
